package org.example.controller;

import jakarta.annotation.Resource;
import org.example.entity.MyUser;
import org.example.service.MyUserDetailsService;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {



    @Resource
    private MyUserDetailsService service;



    public String getUser() {
        return "getUser";
    }


    public String updateUser() {
        return "updateUser";
    }

    public String deleteUser() {
        return "deleteUser";
    }

    @PostMapping("/add")
    public String add(@RequestBody MyUser user) {

        //csrf()默认情况下不支持POST请求
        UserDetails user1 = User.builder()
                .username(user.getName())
                .password("{noop}"+user.getPassword())
                .build();

        service.createUser(user1);
        return "OK createUser";
    }



}
